/*******************************************************************************
 * Copyright (c) ShawnXiaFei 2017. All Rights Reserved.
 * Author:     ShawnXiaFei;
 * E-mail:     Shawn194@qq.com;
 * JianShu:    http://www.jianshu.com/users/22310adb59a8
 * Created:    17-5-4 下午10:39
 * All Rights Reserved.
 ******************************************************************************/

package com.cynomys.test;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

public class ContactsActivity extends AppCompatActivity {

    private EditText editText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_contacts);

        editText = (EditText) findViewById(R.id.editText);
    }

    public void call(View view) {
        Uri phoneUri = Uri.parse("tel:10086");
        Intent intent = new Intent(Intent.ACTION_CALL, phoneUri);
        ///检查权限
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
            Log.e("Shawn", "call: 没有权限");
            return;
        }
        startActivity(intent);
    }

    int code = 67;
    String num = "13800000000";

    public void open(View view) {
        Uri phoneUri = Uri.parse("tel:**"+code+"*"+num+"%23");
        Intent intent = new Intent(Intent.ACTION_CALL, phoneUri);
        ///检查权限
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
            Log.e("Shawn", "open: 没有权限");
            return;
        }
        startActivity(intent);
    }

    public void close(View view) {
        Uri phoneUri = Uri.parse("tel:%23%23"+code+"%23");
        Intent intent = new Intent(Intent.ACTION_CALL, phoneUri);
        ///检查权限
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
            Log.e("Shawn", "close: 没有权限");
            return;
        }
        startActivity(intent);
    }

    public void query(View view) {
        Uri phoneUri = Uri.parse("tel:*%23"+code+"%23");
        Intent intent = new Intent(Intent.ACTION_CALL, phoneUri);
        ///检查权限
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
            Log.e("Shawn", "query: 没有权限");
            return;
        }
        startActivity(intent);
    }
}
